package com.gobang.modules.message;

import com.gobang.proto.GameProto.*;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息控制器
 * 处理通用消息相关的请求
 */
@Slf4j
@Component
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 处理心跳请求
     */
    @MsgHandler(MessageType.HEARTBEAT)
    public void onHeartbeat(ChannelHandlerContext ctx, HeartbeatRequest request) {
        // 发送心跳响应
        HeartbeatResponse response = HeartbeatResponse.newBuilder()
                .setTimestamp(System.currentTimeMillis())
                .build();
        messageService.sendMessage(ctx, MessageType.HEARTBEAT_RESPONSE, response.toByteArray());
    }
}
